﻿using System;
using System.Collections.Generic;
using System.Configuration;
using Citi.GocAttributes.Domain;

namespace Citi.GocAttributes.SchedulerUI
{
    public class ImportManagedGeography : ImportFeed, RoutineBase.IExecutableRoutine
    {
        protected override string FileName { get { return ConfigurationManager.AppSettings["ManagedGeographyFileName"]; } }

        protected override void Import(RoutineBase.ICurrentAction currentAction, DateTime referenceDate, string filePath)
        {
            ManagedGeography.Import(filePath, referenceDate);
        }

        public void Rollback(ref RoutineBase.ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            base.Rollback(ref currentAction, parameters);
        }

        public void Start(DateTime scheduledDate, ref RoutineBase.ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            base.Start(scheduledDate, ref currentAction, parameters);
        }

        public void Stop(ref RoutineBase.ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            base.Stop(ref currentAction, parameters);
        }
    }
    //public class ImportFunction : RoutineBase.IExecutableRoutine
    //{
    //    private readonly string FeedFolder = ConfigurationManager.AppSettings["FeedFolder"];
    //    private readonly string FileName = ConfigurationManager.AppSettings["FunctionFileName"];

    //    public void Rollback(ref RoutineBase.ICurrentAction currentAction)
    //    {

    //    }

    //    public void Start(DateTime scheduledDate, ref RoutineBase.ICurrentAction currentAction, Dictionary<string, object> parameters)
    //    {
    //        var referenceDate = new DateTime(scheduledDate.Year, scheduledDate.Month, 1);

    //        var filePath = Path.Combine(FeedFolder, string.Format(FileName, string.Concat(referenceDate.Year, referenceDate.Month)));

    //        currentAction.Description = string.Format("Looking for file in folder {0}", FeedFolder);

    //        if (File.Exists(string.Concat(filePath, ".xls")))
    //            Import(currentAction, referenceDate, string.Concat(filePath, ".xls"));
    //        else if (File.Exists(string.Concat(filePath, ".xlsx")))
    //            Import(currentAction, referenceDate, string.Concat(filePath, ".xlsx"));
    //        else
    //            currentAction.Description = "No file was found. The routine was set as completed";
    //    }

    //    private static void Import(RoutineBase.ICurrentAction currentAction, DateTime referenceDate, string filePath)
    //    {
    //        currentAction.Description = string.Format("Importing file: {0}", filePath);
    //        Function.ImportFunctions(filePath, referenceDate);
    //        currentAction.Description = "File imported";
    //    }

    //    public void Stop(ref RoutineBase.ICurrentAction currentAction)
    //    {

    //    }
    //}
}
